package common.tree;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2020-11-24
 * Time: 11:59
 */
public class BinarySearchTree<T> {

    private Node<T> root;

    class Node<T>{
        String key;
        T data;
        Node<T> left;
        Node<T> right;

        public Node(String key, T data) {
            this.key = key;
            this.data = data;
        }
    }

    /**
     * 反转BST树，所有节点的左右节点对换
     */
    public void reverse() {
        reverse(root);
    }

    private void reverse(Node<T> root) {
        if (root == null) {
            return;
        }
        Node<T> left = root.left;
        Node<T> right = root.right;

        root.right = left;
        root.left = right;

        reverse(left);
        reverse(right);
    }

}
